package com.nulldev.util.net.dsap;

public enum DSAPRequestServerType {
	/**
	 * TCP (Transmission Control Protocol)
	 */
	TCP((short) 1, "DSAP_TCP") {
		public static final int ID = 1;
	},
	/**
	 * UDP (User Datagram Protocol) 
	 */
	UDP((short) 2, "DSAP_UDP") {
		public static final int ID = 2;
	},
	/**
	 * RUDP (UDP + TCP features)
	 */
	RUDP((short) 3, "DSAP_RUDP") {
		public static final int ID = 3;
	},
	
	;
	
	private final short id;
	private final String sname;
	private DSAPRequestServerType(final short id, final String sname) {
		this.id = id;
		this.sname = sname;
	}
	
	public short id() {
		return this.id;
	}
	
	public boolean isID(final short s) {
		return s == this.id;
	}
	
	public static DSAPRequestServerType get(final short id) {
		for (final DSAPRequestServerType v : values()) {
			if (v.isID(id)) {
				return v;
			}
		}
		return DSAPRequestServerType.TCP;
	}
	
	public static DSAPRequestServerType get(final String text) {
		if (text == null) {
			return DSAPRequestServerType.TCP;
		}
		for (final DSAPRequestServerType v : values()) {
			if (v.sname().equals(text)) {
				return v;
			}
		}
		return TCP;
	}

	public String sname() {
		return this.sname;
	}

}
